home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ETO Development Tools 4
/
ETO Development Tools 4.iso
/
Tools - Objects
/
Virtual User 1.0
/
Example Scripts
/
DrawShapesStress
/
DrawShapesStress.vu
next >
Wrap
Text File
|
1991-01-25
|
13KB
|
365 lines
#
# File DrawShapes.vu
#
# Contains: A test script for DrawShapesVU, the MacApp DrawShapes example program which
# has been built with the Agent VU hook for MacApp. The script selects
# a random shape to draw, draws it to a random size in a random location within
# the window, colors and shades it randomly, and then moves it to a random location in
# the window. It selects a random editing operation after every "Shapes_per_edit"
# shapes are drawn. A number of shapes equal to the global variable "Num_shapes"
# (set to a default of 12) is drawn before the script stops.
#
# This script also has the option of creating output which will recreate the exact
# actions of a script execution in the form of another VU script. In other words, a
# series of println statements will be executed in the script which will effectively
# build another VU script. This script built from output statements will be a series
# of VU commands with all the variables instantiated. An execution of the output
# script should duplicate the actions of the parent script. This is very useful
# for the purposes of reproducibility. If a script of random actions causes a crash
# in the application, the output script can retrace the steps of the script which
# caused the crash.
#
# The creation of this script as output can be enabled by setting the global
# Echo_on to true (default is true).
#
#
# Starting Configuration: In order for the script to run properly, the target should be running
# the DrawShapesVU MacApp demo program 1.0d1, including in the VU package.
#
# THIS SCRIPT WILL NOT WORK WHEN RUNNING AGAINST DrawShapesVU UNDER THE
# THE CURRENT SEEDED ALPHA RELEASE OF SYSTEM 7.0.
#
#
# Conventions: Global variables begin with a capital letter
#
# Written by: Jim Schneider
#
# Copyright: © 1990 by Apple Computer, Inc., all rights reserved.
#
# Change History:
#
# 8/15/90 JAS added echo option to build "retrace" script as output
#
# 8/15/90 JAS took out window scrolling, inserted window drag to known location
#
# 5/15/90 JAS take out infinite loop.
#
# 5/2/90 JAS creation
#
# ********************************************************************************************
#Select the DrawShapes tool from the pallette
task select_pallette_tool(the_tool) begin
global Echo_on;
global Wind_rect;
x:=Wind_rect[1]-20;
y:=Wind_rect[2]+20+(40*(the_tool-1));
move absolute: {x,y}; if Echo_on println "move absolute: ∂{{x},{y}∂};";
click; if Echo_on println "click;";
end;
# ********************************************************************************************
# Pick a random color from the color picker dialog.
task handle_color_picker() begin
global Echo_on;
global Max_scroll_value;
global Rel_color_picker_center;
global Picker_radius;
match[window o:1 r:?color_picker_w_rect];
scroll_value := random(1,Max_scroll_value);
scroll [scrollbar w:[window o:1]] absolute:{scroll_value,Max_scroll_value};
if Echo_on
println "scroll [scrollbar w:[window o:1]] absolute:∂{{scroll_value},{Max_scroll_value}∂};";
wait(1);
if Echo_on
println "wait(1);";
color_picker_center := {Rel_color_picker_center[1] + color_picker_w_rect[1],Rel_color_picker_center[2] + color_picker_w_rect[2]};
x_offset := random(0,(Picker_radius*2)) - Picker_radius;
y_offset := random(0,(Picker_radius*2)) - Picker_radius;
while ((x_offset*x_offset) + (y_offset*y_offset) > Picker_radius*Picker_radius) begin
x_offset := random(0,(Picker_radius*2)) - Picker_radius;
y_offset := random(0,(Picker_radius*2)) - Picker_radius;
end;
x:=color_picker_center[1]+x_offset;
y:=color_picker_center[2]+y_offset;
move absolute: {x,y}; if Echo_on println "move absolute: ∂{{x},{y}∂};";
wait(1); if Echo_on println "wait(1);";
click; if Echo_on println "click;";
select[button t:'OK' w:[window o:1]]!; if Echo_on
println "select[button t:'OK' w:[window o:1]]!;";
end;
# ********************************************************************************************
# Color the selected shape a random color from Colors menu. Screen out the '---' item.
task color_shape() begin
global Echo_on;
global Num_colors;
global Color_sep_item;
global Pick_color_item;
the_color := random(1,Num_colors);
if (the_color = Color_sep_item)
while (the_color = Color_sep_item)
the_color := random(1,Num_colors);
select [menuitem m:[menu t:"Colors"] o:the_color];
if Echo_on
println "select [menuitem m:[menu t:'Colors'] o:{the_color}];";
if (the_color = Pick_color_item)
handle_color_picker();
end;
# ********************************************************************************************
# Shade the selected shape a random shade from the Shades menu
task shade_shape() begin
global Echo_on;
global Shade_menu_posn;
global Shade_cell_size;
the_row := random(1,2);
the_column := random(0,2);
x:=Shade_menu_posn[1];
y:=Shade_menu_posn[2];
move a: {x,y}; if Echo_on println "move a: ∂{{x},{y}∂};";
pressMouse; if Echo_on println "pressMouse;";
wait(1); if Echo_on println "wait(1);";
x:=Shade_cell_size*the_column;
y:=Shade_cell_size*the_row;
move relative: {x,y}; if Echo_on println "move relative: ∂{{x},{y}∂};";
wait(1); if Echo_on println "wait(1);";
releaseMouse; if Echo_on println "releaseMouse;";
end;
# ********************************************************************************************
# Return true if a shape was just drawn (we know this by seeing if the 'Colors' menu is enabled).
# Otherwise, return false.
task test_shape_drawn() begin
match[menu t:'Colors' e:?enabled]!;
return(enabled);
end;
# ********************************************************************************************
# Select a random shape to draw from pallette and draw it at a random position. Size it to a random
# size. Return the coordinates of the shape's rectangle.
task draw_shape() begin
global Echo_on;
global Rect;
global Oval;
global Thick_rect;
global Wind_rect;
prev_speed := mouseSpeed(4); if Echo_on println "prev_speed := mouseSpeed(4);";
the_tool := random(Rect,Thick_rect);
select_pallette_tool(the_tool);
x_coord1 := random(Wind_rect[1],Wind_rect[3]);
y_coord1 := random(Wind_rect[2],Wind_rect[4]);
move absolute: {x_coord1,y_coord1}; if Echo_on println
"move absolute: ∂{{x_coord1},{y_coord1}∂};";
wait(1); if Echo_on println "wait(1);";
pressMouse; if Echo_on println "pressMouse;";
x_coord2 := random(Wind_rect[1],Wind_rect[3]);
y_coord2 := random(Wind_rect[2],Wind_rect[4]);
move absolute: {x_coord2,y_coord2}; if Echo_on
println "move absolute: ∂{{x_coord2},{y_coord2}∂};";
wait(1); if Echo_on println "wait(1);";
releaseMouse; if Echo_on println "releaseMouse;";
mouseSpeed(prev_speed); if Echo_on println "mouseSpeed({prev_speed});";
return({x_coord1,y_coord1,x_coord2,y_coord2});
end;
# ********************************************************************************************
# Move the most current shape to a random position. Pass back new shape rectangle.
task move_shape() begin
global Echo_on;
global Arrow;
global Wind_rect;
global Shape_rect;
x_coord := random(Wind_rect[1],Wind_rect[3]);
y_coord := random(Wind_rect[2],Wind_rect[4]);
select_pallette_tool(Arrow);
x:=(Shape_rect[1]+Shape_rect[3])/2;
y:=(Shape_rect[2]+Shape_rect[4])/2;
move absolute: {x,y}; if Echo_on println "move absolute: ∂{{x},{y}∂};";
pressMouse; if Echo_on println "pressMouse;";
wait(1); if Echo_on println"wait(1);";
move absolute: {x_coord,y_coord}; if Echo_on println "move absolute: ∂{{x_coord},{y_coord}∂};";
wait(1); if Echo_on println"wait(1);";
releaseMouse; if Echo_on println"releaseMouse;";
shape_width := Shape_rect[3]-Shape_rect[1];
shape_height := Shape_rect[4] - Shape_rect[2];
return({x_coord-(shape_width/2),y_coord-(shape_height/2),x_coord+(shape_width/2),y_coord+(Shape_height/2)});
end;
# ********************************************************************************************
# Select random item from edit menu and then possibly do something else, depending on what item
# was selected. Screen out the "---" items.
task do_some_editing() begin
global Echo_on;
global Shape_rect;
global Arrow;
global Num_edit_items;
global Undo_item;
global Edit_sep_item1;
global Cut_item;
global Copy_item;
global Paste_item;
global Clear_item;
global SelectAll_item;
global Edit_sep_item2;
global ShowClipboard_item;
the_item := random(1,Num_edit_items);
while (not ((the_item = Edit_sep_item1) or (the_item = Edit_sep_item2)))
the_item := random(1,Num_edit_items);
match [menuitem m:[menu t:'Edit'] o:the_item e:?enabled];
while (not enabled) begin
the_item := random(1,Num_edit_items);
match [menuitem m:[menu t:'Edit'] o:the_item e:?enabled];
end;
select [menuitem m:[menu t:'Edit'] o:the_item]!;
if Echo_on
println "select [menuitem m:[menu t:'Edit'] o:{the_item}]!;";
if ((the_item = Cut_item) or (the_item = Copy_item)) begin
select [menuitem t:'Paste' m:[menu t:'Edit']]!;
if Echo_on
println "select [menuitem t:'Paste' m:[menu t:'Edit']]!;";
end;
else if (the_item = SelectAll_item) begin # move everything 50 pixels right or left, up or down
x_coord := 50 - random(1,100);
y_coord := 50 - random(1,100);
select_pallette_tool(Arrow);
x := (Shape_rect[1]+Shape_rect[3])/2;
y := (Shape_rect[2]+Shape_rect[4])/2;
move absolute: {x,y}; if Echo_on println "move absolute: ∂{{x},{y}∂};";
pressMouse; if Echo_on println "pressMouse;";
wait(1); if Echo_on println "wait(1);";
move relative: {x_coord,y_coord}; if Echo_on
println "move relative: ∂{{x_coord},{y_coord}∂};";
wait(1); if Echo_on println "wait(1);";
releaseMouse; if Echo_on println "releaseMouse;";
end;
else if (the_item = ShowClipboard_item) begin
wait(1); if Echo_on println "wait(1);";
close [window o:1]; if Echo_on println "close [window o:1];";
end;
end;
# ********************************************************************************************
# clean up the DrawShapes window
task clean_up_window() begin
global Echo_on;
match [menuitem t:"Select All" m:[menu t:"Edit"] e:?enabled];
if (enabled) begin
select[menuitem t:"Select All" m:[menu t:"Edit"]];
if Echo_on
println 'select[menuitem t:"Select All" m:[menu t:"Edit"]];';
select[menuitem t:"Clear" m:[menu t:"Edit"]];
if Echo_on
println 'select[menuitem t:"Clear" m:[menu t:"Edit"]];';
end;
end;
# ********************************************************************************************
# Get the rectangle representing the DrawShape's window content region
task get_wind_cnt_rect() begin
global Pix_left;
global Pix_top;
global Pix_right;
global Pix_bottom;
match [window o:1 r:?window_rect]!;
return({window_rect[1]+Pix_left,window_rect[2]+Pix_top,window_rect[3]-Pix_right,window_rect[4]-Pix_bottom});
end;
##### EXECUTION STARTS HERE ######
# make this true if you want record of scripts actions in VU scripting languare
# printed to standard output
Echo_on := true;
# variable Num_shapes determines number of shapes drawn
Num_Shapes := 12;
# number of shapes to draw before a random editing operation takes place
Shapes_per_edit := 3;
# indices into pallette
Arrow := 1;
Rect := 2;
Oval := 3;
Thick_rect := 4;
# misc. globals
Color_sep_item := 8;
Pick_color_item := 9;
Max_scroll_value := 32767;
Rel_color_picker_center := {293,137};
Picker_radius := 100;
Shade_menu_posn := {125,10};
Shade_cell_size := 25;
# pixels between window rect and content rect
Pix_top := 21;
Pix_left := 41;
Pix_bottom := 17;
Pix_right := 17;
#edit menu items
Num_edit_items := 9;
Undo_item := 1;
Edit_sep_item1 := 2;
Cut_item := 3;
Copy_item := 4;
Paste_item := 5;
Clear_item := 6;
SelectAll_item := 7;
Edit_sep_item2 := 8;
ShowClipboard_item := 9;
match [menu t:"Colors" i:?Item_list]!;
Num_colors := card(Item_list); # get number of items in Colors menu
match [menu t:"edit" i:?Item_List]!;
Num_edit_items := card(Item_list); # get number of items in Edit menu;
clean_up_window();
# this is done to ensure that absolute moves in output script will match those made in
# running this script
drag [window o:1] a:{5,25};
if Echo_on
println 'drag [window o:1] a:{5,25};';
Wind_rect := get_wind_cnt_rect(); # get window's content rectangle
for i := 1 to Num_shapes begin
Shape_rect := draw_shape();
if test_shape_drawn() begin
color_shape();
shade_shape();
Shape_rect := move_shape();
if ((i mod Shapes_per_edit) = 0)
do_some_editing();
end;
end;